package t4dao;

import java.util.List;
import t4bean.FruitBean;
import t4bean.MoneyRecordBean;
import t4bean.PurchaseRecordBean;

public class SetSql {
	public String setSql(FruitBean fruit, String sql, List<Object> list, int m) {
		int n = 0;
		if (fruit.getName() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "name=?";
			list.add(fruit.getName());
			n = m;
		}
		if (fruit.getPrice() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "price=?";
			list.add(fruit.getPrice());
			n = m;
		}
		if (fruit.getCost() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "cost=?";
			list.add(fruit.getCost());
			n = m;
		}
		if (fruit.getNumber() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "number=?";
			list.add(fruit.getNumber());
			n = m;
		}
//		System.out.println(sql);
		return sql;
	}

	public String setSql(MoneyRecordBean mrb, String sql, List<Object> list, int m) {
		int n = 0;
		if (mrb.getFruitName() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "fruitname=?";
			list.add(mrb.getFruitName());
			n = m;
		}
		if (mrb.getSellingTime() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "sellingtime=?";
			list.add(mrb.getSellingTime());
			n = m;
		}
		if (mrb.getNumber() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "number=?";
			list.add(mrb.getNumber());
			n = m;
		}
		if (mrb.getMoney() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "money=?";
			list.add(mrb.getMoney());
			n = m;
		}
		if (mrb.getCost() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "cost=?";
			list.add(mrb.getCost());
			n = m;
		}
		return sql;
	}

	public String setSql(PurchaseRecordBean prb, String sql, List<Object> list, int m) {
		int n = 0;
		if (prb.getFruitName() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "fruitname=?";
			list.add(prb.getFruitName());
			n = m;
		}
		if (prb.getPurchaseTime() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "purchasetime=?";
			list.add(prb.getPurchaseTime());
			n = m;
		}
		if (prb.getNumber() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "number=?";
			list.add(prb.getNumber());
			n = m;
		}
		if (prb.getCost() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "cost=?";
			list.add(prb.getCost());
			n = m;
		}
		return sql;
	}
}
